home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / sbin / gconf-schemas < prev    next >
Encoding:
Text File  |  2010-11-06  |  3.0 KB  |  93 lines

  1. #! /usr/bin/python
  2. #
  3. # copyright (c) 2006 Josselin Mouette <joss@debian.org>
  4. # Licensed under the GNU Lesser General Public License, version 2.1
  5. # See COPYING for details
  6.  
  7. from optparse import OptionParser
  8. import sys,os,os.path,shutil,tempfile
  9.  
  10. parser = OptionParser(usage="usage: %prog --[un]register file1.schemas [file2.schemas [...]]")
  11.  
  12. parser.add_option("--register", action="store_true", dest="register",
  13.                   help="register schemas to the GConf database",
  14.                   default=None)
  15. parser.add_option("--unregister", action="store_false", dest="register",
  16.                   help="unregister schemas from the GConf database",
  17.                   default=None)
  18. parser.add_option("--register-all", action="store_true", dest="register_all",
  19.                    help="clean up the GConf database and register all schemas again",
  20.                    default=False)
  21. parser.add_option("--no-signal", action="store_false", default=True, dest="signal",
  22.                   help="do not send SIGHUP the running gconfd-2 processes")
  23. (options, args) = parser.parse_args()
  24.  
  25. if options.register==None and not options.register_all:
  26.   parser.error("You need to specify --register or --unregister.")
  27.  
  28. if 'DPKG_RUNNING_VERSION' in os.environ and not options.register_all:
  29.     # This is what happens when we are called in an obsolete postinst/prerm script
  30.     # Do nothing, it will be done in the trigger
  31.     sys.exit(0)
  32.  
  33. schema_location="/usr/share/gconf/schemas"
  34. defaults_dest="/var/lib/gconf/defaults"
  35.  
  36. schemas = [ ]
  37. if options.register_all:
  38.   for f in os.listdir(schema_location):
  39.     if f.endswith(".schemas"):
  40.       schemas.append(os.path.join(schema_location,f))
  41. else:
  42.   for schema in args:
  43.     if not os.path.isabs(schema):
  44.       schema=os.path.join(schema_location,schema)
  45.     if os.path.isfile(schema):
  46.       schemas.append(schema)
  47.     else:
  48.       sys.stderr.write('Warning: %s could not be found.\n'%schema)
  49.  
  50. if os.geteuid():
  51.   parser.error("You must be root to launch this program.")
  52.  
  53. if options.register_all:
  54.   options.register=True
  55.   for f in os.listdir(defaults_dest):
  56.     os.remove(os.path.join(defaults_dest,f))
  57.   open(os.path.join(defaults_dest,"%gconf-tree.xml"),"w").close()
  58.  
  59. if schemas:
  60.     tmp_home=tempfile.mkdtemp(prefix='gconf-')
  61.     env={'HOME': tmp_home,
  62.          'GCONF_CONFIG_SOURCE': 'xml:readwrite:'+defaults_dest}
  63.     if options.register:
  64.       arg='--makefile-install-rule'
  65.     else:
  66.       arg='--makefile-uninstall-rule'
  67.  
  68.     fd = os.open("/dev/null",os.O_WRONLY)
  69.     save_stdout=os.dup(1)
  70.     os.dup2(fd,1)
  71.     os.close(fd)
  72.     res=os.spawnvpe(os.P_WAIT,'gconftool-2',['gconftool-2',arg]+schemas,env)
  73.     os.dup2(save_stdout,1)
  74.     os.close(save_stdout)
  75.  
  76.     shutil.rmtree(tmp_home)
  77.  
  78.     if(res):
  79.       sys.exit(res)
  80.  
  81. if options.register and options.signal:
  82.   # tell running processes to re-read the GConf database
  83.   import signal
  84.   try:
  85.     pids=os.popen('pidof gconfd-2').readlines()[0].split()
  86.     for pid in pids:
  87.       try:
  88.         os.kill(int(pid),signal.SIGHUP)
  89.       except OSError:
  90.         pass
  91.   except IndexError:
  92.     pass
  93.